I'm trying to create a connection string in dreamweaver with MySQL. It is my first tutorial with php and MySQL so excuse me if I'm missing something. This is my connectionString code:
<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_explorecalifornia= "mysql:host=localhost;
dbname=explorecalifornia;charset=utf8";
$database_explorecalifornia = "explorecalifornia";
$username_explorecalifornia = "root";
$password_explorecalifornia = "";
$explorecalifornia = mysql_pconnect($hostname_explorecalifornia,
$username_explorecalifornia, $password_explorecalifornia) or trigger_error
(mysql_error(),E_USER_ERROR);
?>
I'm getting this error :
Deprecated: mysql_pconnect(): The mysql extension is deprecated and will
be removed in the future: use mysqli or PDO instead in
C:\wamp\www\dwwithphp\Connections\explorecalifornia.php on line 9
I tried using mysql_connect(),mysqli() and PDO() but I also have an error:
Warning: mysqli::mysqli(): php_network_getaddresses: getaddrinfo
failed: No such host is known. in
C:\wamp\www\dwwithphp\Connections\explorecalifornia.php on line 9
similar error for the other methods. the last two days I've been searching for a solution with no luck. I'M using :Apache/2.4.9 (Win64) PHP/5.5.12,MySQL 5.6.17 and Dreamweaver cs5
Edit
I tried uninstalling wamp server and reinstalling it but it didn't work I've got the same errors. I don't know what to do next, i really need help.
The mysql php APIs deal with constructing the connection string mysql:host=hostname
stuff internally.
Friends don't help friends connect with the old, nasty, deprecated, insecure mysql_
api.
To connect with mysqli, you want something like this:
$hostname = "localhost";
$database = "explorecalifornia";
$username = "CONCEALED";
$password = "CONCEALED";
$conn = new mysqli($hostname, $username, $password, $database);
if ($conn ->connect_error) {
die('Connect Error (' . $conn ->connect_errno . ') '
. $conn ->connect_error);
$conn->set_charset('utf8') || die "cannot set character set.";
Try this ;-)
STEP One: The connexion in the DB (connexion.php)
<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_connexion = "localhost";
$database_connexion = "apc";
$username_connexion = "root";
$password_connexion = "";
$connexion = mysqli_connect($hostname_connexion, $username_connexion, $password_connexion) or trigger_error(mysqli_error(),E_USER_ERROR);
?>
STEP TWO: In your (exemple.php)
<?php require_once('connexion.php'); ?>
<?php
mysqli_select_db( $connexion, $database_connexion);
$query_ecoles = "SELECT * FROM exempletable1";
$ecoles = mysqli_query($connexion, $query_ecoles) or die(mysqli_error());
$row_ecoles = mysqli_fetch_assoc($ecoles);
$totalRows_ecoles = mysqli_num_rows($ecoles);
?>
100 % working,
The idea is to change the mysql by mysqli and the order of the connection variable in the example.php page.....
</div>