Php cannot connect to mysql. I am a newbie. I connected to the test table create & nbsp; table & nbsp; test (id & nbsp; int, & nbsp; name & nbsp; in the test2 database; varchar (255) and then write code in zendsudio (the code is written in the book) & nbsp ;:& lt ;? Php $ connmysqli_init (); if (! $ Co php failed to connect to mysql
I am a newbie, connecting to a test table in the test2 database
Create table test
(Id int,
Name varchar (255)
)
Then write the code in zendsudio (the code is written in the book ):
$ Conn = mysqli_init ();
If (! $ Conn)
{
Echo "mysqli_init error ";
Exit (0 );
}
$ Ret = mysqli_real_connect ($ conn, "localhost", "root", "840803 ",
"Test2", 3306, "test", MYSQLI_CLIENT_FOUND_ROWS );
If ($ ret)
{
Echo "mysqli_real_connect error! ";
Exit (0 );
}
$ SQL = 'Insert into test values (1, "tom ")';
$ Ret = mysqli_query ($ conn, $ SQL );
If (! $ Ret)
{
Echo "mysqli_query error! ";
Exit (0 );
}
$ SQL = 'select * from test ';
$ Ret = mysqli_query ($ conn, $ SQL );
While ($ row = mysqli_fetch_array ($ ret, MYSQLI_ASSOC ))! = NULL)
{
Echo "id:". $ row ['id']."
";
Echo "name". $ row ['name']."
";
}
?>
After running:
Mysqli_real_connect error!
What's wrong with this? could you please give me some advice? urgent, online!
------ Solution --------------------
If ($ ret)
{
Echo "mysqli_real_connect error! ";
Exit (0 );
}
After the connection is successful, it does not enter here. Where does it enter? Yes if (! $ Ret?
------ Solution --------------------
if($ret)
{
echo "mysqli_real_connect error!";
exit(0);
}
An error is reported if $ ret does not exist.
If (! $ Ret)
{
Echo "mysqli_real_connect error! ";
Exit (0 );
}