I got ID for a record from a db and stored in $foo. I'm able to mkdir with name using value in $foo. For example if echo $foo; = 29 my dir name is 29. I want to create db in the same way, but not working and no error.
$conn = new PDO("mysql:host=$db_host1;dbname=$db_database1", $db_username1, $db_password1);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "INSERT INTO COMPANY (COMPANY_NAME, COMPANY_STREET, COMPANY_CITY, COMPANY_ZIP, COMPANY_STATE, COMPANY_COUNTRY, COMPANY_PHONE, COMPANY_EMAIL, password, securityq, securitya, vercode)
VALUES ('$CNAME', '$CSTREET', '$CCITY', '$CZIP', '$CSTATE', '$CCOUNTRY', '$CPHONE', '$CEMAIL', '$password', '$securityq', '$securitya', '$vercode')";
// use exec() because no results are returned
$conn->exec($sql);
echo "New record created successfully";
//select company id where company name is what was entered now
$sql = "Select COMPANY_ID FROM COMPANY where COMPANY_EMAIL='$CEMAIL'";
$CID=mysql_query($sql) or die ('query failed'.mysql_error());
while($row=mysql_fetch_assoc($CID)){
//echo $row['COMPANY_ID'];
$foo=$row['COMPANY_ID'];
}
// Create database
require_once 'config2.php';
$conn2 = new PDO("mysql:host=$db_host1", $db_username1, $db_password1);
// set the PDO error mode to exception
$conn2->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if (FALSE===mysql_connect($db_host1, $db_username1, $db_password1)) {
die('Unable to connect to the database !');
}
mysql_connect($db_host1, $db_username1, $db_password1);
mysql_query("CREATE DATABASE '". $foo ."'");
echo $newdb;
mkdir("./users/$foo/", 0755);
I also tried
mysql_query("CREATE DATABASE $foo");
but wont work. If I replace $foo with test or something
mysql_query("CREATE DATABASE test");
, db name test is created! Please help.