Log in

View Full Version : How to connect database!



nhocxinh10x
08-19-2014, 07:35 AM
I'm learning about php language. Making statements such as how to connect to mysql database.

james438
08-19-2014, 05:51 PM
Did you have a question?

Deadweight
08-20-2014, 01:21 PM
I think he is asking how do you connect to a database in php:
Here is a good way to start:
http://www.w3schools.com/php/php_mysql_connect.asp

Bionic
09-02-2014, 05:08 PM
you really need to ignore the above post to use MYSQL or MYSQLI they are depricated in php5.3 adn GONE in php5.4

if you use mysql(i) you will Never be able to upgrade beyond php 5.3 unless you rewrite your script.

james438
09-25-2014, 05:51 PM
you really need to ignore the above post to use MYSQL or MYSQLI they are depricated in php5.3 adn GONE in php5.4

if you use mysql(i) you will Never be able to upgrade beyond php 5.3 unless you rewrite your script.

As I said before (http://www.dynamicdrive.com/forums/showthread.php?77239-I-NEED-HELP-MY-LOGIN-PHP-redirects-to-blank-page-logon-php&p=308559#post308559) that statement is just not true. Traq wrote a very good post (http://www.dynamicdrive.com/forums/showthread.php?74543-Updating-deprecated-code-for-MySQL-5-5&p=297484#post297484) on this topic.

Mysql_connect is deprecated, but not removed in any version of php. Mysqli_connect is actively supported and encouraged and there are no plans to remove it for the foreseeable future. The same is true for PDO. reference (http://php.net/manual/en/mysqli.overview.php) scroll down to the comparison chart for the status on each of the three main methods for connecting to MySQL using php, which includes mysql_connect.

Deadweight's response is perfectly valid.

harryblossom30
10-15-2014, 12:43 PM
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
die('Not connected');
}


$db_selected = mysql_select_db('foo', $link);
if (!$db_selected) {
die ('database is not selected');
}