studentici Posted November 6, 2017 Share Posted November 6, 2017 (edited) Me learning php easyph have version 3.7, easyphp not that easy to me so i have a question. I can connect to mysql but can not detect database, this must be a basic tweak for those who know the ropes. <?php $connection = mysql_connect('localhost','root','') ; $database = mysql_select_db('loginapp'); if($connection){ echo "CONNECTED" ; } else {die('Error.');} if($database){'DATABASE FOUND';} else { die("DATABASE NOT FOUND");} ?> $connection = mysql_connect('localhost','root','') ; WORKS $database = mysql_select_db('loginapp'); DOES NOT WORK so there is some confirmed connection. Edited November 6, 2017 by studentici more words Link to comment Share on other sites More sharing options...
Ingolme Posted November 6, 2017 Share Posted November 6, 2017 My only guess is that there is no database named "loginapp". You forgot an echo statement here, so this line of code won't show anything: if($database){'DATABASE FOUND';} You should not be using the mysql_* functions, they have long been deprecated in favor of proper secure database libraries, as of PHP 7 they have been completely removed. For database operations, check out PDO http://php.net/PDO Link to comment Share on other sites More sharing options...
codeminer Posted November 8, 2017 Share Posted November 8, 2017 (edited) <?php $servername = "localhost"; $username = "YOUR USERNAME"; $password = "LEAVE BLANK IF YOU HAVENT CREATED PASSWORD"; // if you don't have a db just comment out $dbname //you will also need to remove it from $conn=new mysqli //(make sure to take off the comma at the end of password) $dbname = "YOUR DB NAME"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // you can remove the echo and add whichever kind of STATEMENT you like echo "Connected successfully"; mysqli_close($conn); ?> Edited November 8, 2017 by codeminer Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now