Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I finally got it working.</p> <p>Why was i getting that error? I installed XAMPP and started mysql server from there and i was using the command prompt of some other mysql which i have installed.</p> <p>How to create a table and access it using php? Following is what you have to do! Install XAMPP Once you have installed it then run "xampp-control.exe" Start the mysql service in that controller. Open the mysql command prompt in superuser mode using C:\XYZ\xampp\mysql\bin> mysql.exe -uroot</p> <p>mysql shell will get open. Create user using: mysql> CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'mypass';</p> <p>Create Database using: mysql> Create DATABASE my_db;</p> <p>Set the database as your current database: mysql> use my_db;</p> <p>Create a table using: mysql> CREATE TABLE users ( user varchar(255) NOT NULL, password varchar(255) NOT NULL );</p> <p>Insert a value in that table: mysql> INSERT INTO users values ( 'usernew' , 'password' );</p> <p>Now writing the php code to access this:</p> <pre><code>&lt;?php $user_name = "newuser"; $password = "mypass"; $database = "my_db"; $server = "localhost"; $db_handle = mysql_connect($server, $user_name, $password) or die(mysql_error()); $db_found = mysql_select_db($database, $db_handle) or die(mysql_error()); if ($db_found) { print "Database Found "; } else { print "Database NOT Found "; } $query = "SELECT * FROM users"; $result = mysql_query($query); while ($line = mysql_fetch_array($result)) { foreach ($line as $value) { print "$value\n"; } } $queryInsert = "INSERT INTO users values('mohan', 'mohan123')"; $result = mysql_query($queryInsert); mysql_close($db_handle); ?&gt; </code></pre> <p>Hope it helps! :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload