0

when iam trying to create database, it is showing error.

this is the code. 1.<?php 2.mysqli_connect("localhost","root", "admin") or die (mysqli_error()); 3.echo "connect ed to server success <br>"; 4.$query="CREATE DATABASE mydatabase1"; 5.mysqli_query($query) or die (mysqli_error ()); 6.echo "database create successful"; 7.mysqli_close (); ?> and this is the error: connect ed to server success Warning: mysqli_query() expects at least 2 parameters, 1 given in /storage/sdcard0/htdocs/db1.php on line5

29th Jun 2017, 4:24 PM
Krishna Teja
Krishna Teja - avatar
4 Respostas
+ 1
<?php $dbConn = mysqli_connect("localhost","root", "admin") or die (mysqli_error()); echo "connect ed to server success <br>"; $query="CREATE DATABASE mydatabase1"; mysqli_query($dbConn, $query) or die (mysqli_error ()); echo "database create successful"; mysqli_close ($dbConn); ?>
29th Jun 2017, 5:17 PM
AgentSmith
+ 2
Store your mysqli_connect to a variable and then use that variable in your query. This will let the query connect and do its thing. Example: $databaseConnection = mysqli_connect("localhost","root", "admin"); mysqli_query($databaseConnection, $query);
29th Jun 2017, 4:37 PM
AgentSmith
+ 2
@netkos thank you fot reply...but where should I place the code ?
29th Jun 2017, 5:02 PM
Krishna Teja
Krishna Teja - avatar
0
@Netkos yeah it is working! ! Thank you very much.
29th Jun 2017, 5:31 PM
Krishna Teja
Krishna Teja - avatar