简体   繁体   中英

Having Problems With PHP Connection

This is the code that connects to my SQL database. I'm new with this stuff and it seems to be semi-working but certain features on my website still don't work.

<?php
$con = mysql_connect("localhost","username","password");
$select_db = mysql_select_db('database1',$con);
/*$con = mysql_connect("localhost","username2","password2");
$select_db = mysql_select_db('database2',$con);*/
?>

This is the site in question: http://tmatube.com keep in mind the credentials above are filled in with what the programmer used for testing on his own server... ;) unfortunately I don't have access to him for support anymore.

Anyway, here's my thoughts on how this code needs to be edited maybe someone can chime in and let me know if I'm correct in my assumptions:

<?php
$con = mysql_connect("localhost","username1","password1"); -------------<<< leave this line 
$select_db = mysql_select_db('DATABASE_NAME_HERE',$con);
/*$con = mysql_connect("localhost","DB_USERNAME_HERE","DB_PASSWORD_HERE");
$select_db = mysql_select_db('DATABASE_NAME_HERE',$con);*/
?>

Ok - now on to a few problems I noticed...

What does this do? /* code here */? It doesn't work at all if I leave that bit in.

Why is it connecting to database twice? and is it two separate databases?

$select_db = mysql_select_db('DATABASE_NAME_HERE',$con); <<<---- single '

When I tried to see if that line was correct the examples I saw had quotes like this

$select_db = mysql_select_db("DATABASE_NAME_HERE",$con); <<<---- double "

Which one is right?

Here is php mysql connect with mysqli :

<?php 
$link = mysqli_connect("myhost","myuser","mypassw","mybd");
?>

No difference here with ' or ". (Anyway use mysqli and you can the wanted db as 4th parameter.) php quotes

/* comment */ is a commented out so the php does not care what is inside so only 2 first rows of are affecting (they are same mysql database on the local machine and 2 different user + password combinations). Comment in general are used to explain the code or removing part of the code with out erasing it. php commenting

He didn't leave it out. What he did was leave the database to be connected using the root, which has no password. The other connection (which is commented out) is using another user, rajvivya_video, with a password defined.

In testing it MIGHT be okay to connect to root and leave it without password, but even that is not recommended, since its so easy to work with a user and password defined (besides root).

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM