0

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?

joran
  • 169,992
  • 32
  • 429
  • 468

2 Answers2

0

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

Community
  • 1
  • 1
Repeat Spacer
  • 373
  • 3
  • 17
  • ok so this should work correct? – apexmateria Jul 29 '13 at 00:38
  • --------------------------- -------------------------- PS anyone willing to help me with this issue add me on skype user: pbomarketing --- willing to pay $20 by paypal. hopefully that doesn't break any rules lol I need a bit of help on teamviewer. – apexmateria Jul 29 '13 at 00:39
  • Yes. what you said will work. even though its not good way cause the mysql_connect is no more supported and not safe. Moving to mysqli or maybe better pdo prepared statements is very proposed [link](http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access/) – Repeat Spacer Jul 29 '13 at 01:41
  • If you still want to stick in mysql_connect I propose to read this short tutorial [link](http://php.about.com/od/phpwithmysql/ss/mysql_php.htm) or similar [link](http://www.google.com/search?q=php+mysql+tutorial&ie=utf-8) – Repeat Spacer Jul 29 '13 at 01:48
  • Awesome, thanks for making the effort to help me out. That's a great tutorial. Real easy to understand. Would rep you if I could. Cheers! – apexmateria Jul 29 '13 at 03:03
  • You can select this as a correct answer and I will get my reward. It was good that i could help! – Repeat Spacer Jul 29 '13 at 14:49
0

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).

Steve Ford
  • 58
  • 1
  • 4