I'm following a tutorial on the net on PHP and MySQL.
I'm using Linux. I'm trying to establish a connection to a database but it is not working. I have my database:
create database test;
create table user(name text, pass text);
insert into user values('john', '123');
and then my php:
<?php
$_host = "localhost";
$_dbuser = "root"
$_dbpass = "";
$_dbname = "test";
@mysql_connect("$_host", "$_dbuser", "$_dbpass") or die("could not connect");
@mysql_select_db("$_dbname") or die("no database");
echo "connection stablished";
?>
And the output of my file is just a blank tab on the browser. What should I do to solve this? What am I doing wrong?
Thank you in advance. I'm very new to web programming.
$_host = "localhost";
$_dbuser = "root"
$_dbpass = "";
$_dbname = "test";
$link = mysqli_connect($_host, $_dbuser, $_dbpass, $_dbname);
if (!$link) {
die('Connect Error (' . mysqli_connect_errno() . ') '
. mysqli_connect_error());
}
echo "connection stablished";
Now...
mysqli_*
functions as mysql_*
are deprecated. $link
variable later for queries.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.