我是初学者,只是从这个youtube课程中吸取了一些教训:
https://www.youtube.com/watch?v=TSX72_O7QYY&index=116&list=PL442FA2C127377F07
我已经写了这段代码。
<?php
$db_host = 'localhost';
$db_username = 'root';
$db_password = 'awesome11';
$db_connError = '<br>Cannot connect<br>';
$db_connConf = '<br>Connect to db<br>';
$db_name = 'codelib';
$db_table = 'codes';
$db_conn = mysqli_connect($db_host,$db_username,$db_password,$db_name);
if($db_conn){
mysqli_select_db($db_conn,$db_table);
echo $db_connConf;
}else{
echo $db_connError;
}
$query = "SELECT 'id' FROM `codes'";
if($run = mysqli_query($db_conn,$query)){
echo 'query is ok';
}else{
echo 'query failed';
}
?>
函数mysqli_connect()
运行正常。但是msqli_query()
不起作用。它总是说查询失败。
除了msqli_query()
之外,简单msqli()
也永远不会有效!
我甚至无法创建像这样的变量:
$mysqli = new mysqli($db_host,$db_username,$db_password,$db_name)
答案 0 :(得分:1)
您的查询行中有拼写错误,请更改以下内容:
$query = "SELECT 'id' FROM `codes'";
到此:
$query = "SELECT `id` FROM `codes`";
您使用单引号(&#39;)而不是反向引号(`)