I'm learning about php language. Making statements such as how to connect to mysql database.
Printable View
I'm learning about php language. Making statements such as how to connect to mysql database.
Did you have a question?
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
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 that statement is just not true. Traq wrote a very good post 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 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.
PHP Code:$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');
}