Im attempting to construct to new mysql tables at once:
public function connect() {
mysql_connect($this->host,$this->username,$this->password) or die("Could not connect. " . mysql_error());
mysql_select_db($this->table) or die("Could not select database. " . mysql_error());
return $this->buildDB();
}
private function buildDB() {
$sql = <<<MySQL_QUERY
CREATE TABLE IF NOT EXISTS projects (
title VARCHAR(300),
projectid VARCHAR(100)
)
CREATE TABLE IF NOT EXISTS owners (
projectid VARCHAR(100),
owners VARCHAR(150)
)
MySQL_QUERY;
return mysql_query($sql);
}
This maybe sort of a novice question, but I am having trouble seeing why this wont work - any ideas?
EDIT: Updated to incorporate @mellamokb idea about splitting up the queries
private function buildDB() {
$sql = <<<MySQL_QUERY
CREATE TABLE IF NOT EXISTS projects (
title VARCHAR(300),
tags VARCHAR(390),
description TEXT,
created VARCHAR(100),
projectimg VARCHAR(150),
savethumb VARCHAR(150),
owners VARCHAR(150),
projectid VARCHAR(100),
projecturl VARCHAR(150)
);
CREATE TABLE IF NOT EXISTS owners (
projectid VARCHAR(100),
owners VARCHAR(150)
)
MySQL_QUERY;
$arr = split(";", $sql);
foreach($arr as &$value) {
return mysql_query($value);
}
So, I updated the original question using split and then a foreach statement to iterate through each 'CREATE TABLE'. Unfortunately only the first table (projects) gets created. Any ideas what could be going on