关于 PHP 与 MYSQL的链接
生活随笔
收集整理的這篇文章主要介紹了
关于 PHP 与 MYSQL的链接
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
鏈接的語句?
???????????????????????????????????? ? ? ? ? ? ? ? ? ? ? ? ? ? ? mysql主機???????????? 用戶名???? 用戶的密碼??? 數據庫的名字
???????????????????????????????????????? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 地址
<?php ↑ ↑ ↑ ↑ $con = mysql_connect("localhost","peter","abc123","tast"); if (!$con){die('Could not connect: ' . mysql_error());}// some code?>例子:
<?php
require_once 'application/view.php';
class LoginController {
??? public function main($vars=array()){
??????? switch ($vars["action"]){
??????????? case "loginAction":$this->loginAction($vars);break;//登錄
??????? }
??? }
??? public function loginAction($vars=array()) {
??????? $userName = $vars["user_phone"];
??????? $userPassword = $vars["userPassword"];
???????? ?
?????? $con = mysqli_connect("localhost","root","","tast"); ""表示沒有設置密碼
?????? if( !$con ) {
?????????? die('Could not connect: ' . mysql_error());
?????? }
?????? $ccc=array();
?????? $apple="select * from ppp;"; → 是MYSQL的查詢語句
?????? $banana=mysqli_query($con,$apple); ($con是鏈接數據庫的鑰匙)
?????? while($row = mysqli_fetch_array($banana)){
//??????????? var_dump($row);
?????????? $ccc[]= $row;
?????? }
//??????? var_dump($a) ;
??????? $ASB=false;
?????? for ($i=0;$i<count($ccc);$i++){
??????????? $a=$ccc[$i]["ppp_id"];
??????????? $b=$ccc[$i]["ppp_title"];
//???????????? var_dump($a); 測試函數的
//???????????? var_dump($b);
??????????? if($userName==$a){
??????????????? if($userPassword==$b){
????????????????? $ASB=true;
??????????????? }
//???????????????? else{
//???????????????????? $view = new View("/application/view/pc/login.php");
//???????????????????? echo "<script>alert('神知道你錯了啥?')</script>";
// //???????????????????? $view->assign("info","請輸入正確的用戶名和密碼");
//???????????????? }
??????????? }
//???????????? else{
//???????????????? $view = new View("/application/view/pc/login.php");
//???????????????? echo "請輸入賬號和密碼!!";
//???????????? }
?????? }
?????? if($ASB==false){
?????????? if($userName==''){
?????????????? if($userPassword==''){
//??????????????? $view = new View("/application/view/pc/login.php");
?????????????? echo '<script language="javascript">alert("請注冊賬號!");window.history.back();</script>';
?????????????? exit(); ↓
?????????????? } (非常好用,直接跳轉到登錄頁面。)
???????????? ?
?????????? }if($userName==''){
?????????????? echo '<script language="javascript">alert("賬號不能為空!");window.history.back();</script>';
?????????????? exit();
???????????? ?
?????????? }if($userPassword==''){
?????????????? echo '<script language="javascript">alert("密碼不能為空!");window.history.back();</script>';
????????????? ?
?????????? }if($userName==$a){
?????????????? if($userPassword!=$b)
?????????????? {
?????????????? echo '<script language="javascript">alert("請輸入正確密碼!");window.history.back();</script>';
?????????????? exit();
?????????????? }
?????????? }
????????? ?
?????? }else{
????????? echo"登錄成功";
?????? }
??? }
}
?>
轉載于:https://www.cnblogs.com/Xiao-fang0804/p/7814844.html
總結
以上是生活随笔為你收集整理的关于 PHP 与 MYSQL的链接的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 坦克500PHEV展现新能源越野价值
- 下一篇: kafka 分区和副本以及kafaka