Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6661589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:17:55+00:00 2026-05-26T02:17:55+00:00

Im attempting to construct to new mysql tables at once: public function connect() {

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:17:56+00:00Added an answer on May 26, 2026 at 2:17 am

    mysql_query cannot run multiple statements in a single call according to the docs: (emphasis mine)

    mysql_query() sends a unique query (multiple queries are not
    supported
    ) to the currently active database on the server that’s
    associated with the specified link_identifier.

    You either need to split up the statements into separate calls to mysql_query, or make use of the mysqli library and mysqli_multi_query instead.

    If you do go the splitting queries route with mysql_query, one easy way to do this is to terminate your statements with ; as normal in your single script, and then run a PHP command to split around the ; (like split or explode). Then loop through each of the output strings and execute them one at a time.

    EDIT: Regarding your update: you need to move the return statement to outside the bottom of the loop, otherwise it returns to the caller of the function immediately after the first query.


    Related SO questions (Remarkable what you can find with Google if you try, isn’t it):

    • How to execute two mysql queries as one in PHP/MYSQL?
    • PHP MySQL Multi-statement works on my webpage but not on XAMPP
    • How do you do multiple SQL statments in one mysql_query?
    • Run multiple MySQL queries from PHP | Why is this not working?
    • How can I put two queries in one mysql_query?
    • mysqli multiple queries – set variable produces boolean error/how to skip this?
    • Execute multiple sql delete query in mysql for php
    • Cannot execute two mysql queries at once in PHP
    • mysql query works when ran in phpmyadmin, but returns an error when ran in php
    • Returns false when running this query
    • mysql muliple queries in one statement
    • ahh.. so many.. SO MANY!!
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to construct a Django application that models an existing set of tables.
I am attempting to construct my own date picker using code from several sources.
I am attempting to construct my own date picker using code from several sources.
Attempting to use the data series from this example no longer passes the JSONLint
I've constructed a database in MySQL and I am attempting to map it out
I'm attempting to construct rich-text where the first part says Looking for: and is
I'm attempting to be more secure and start using PDO and prepared statements. This
I'm attempting to construct a web service that allows for RESTful requests to return
I am new to OOP and I have been working on this example but
I am attempting to use the following PHP class: <?php class Service { public

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.