If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Sql help

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-21-09, 00:36
adam119 adam119 is offline
Registered User
 
Join Date: Sep 2009
Posts: 1
Sql help

Hello,

I have a script thats already done however I'm just missing sql file that need to be imported into the database in either for the script to run. How to creat a sql using this:
Code:
if (!defined('STARTED'))
    die('No direct access.');

/**
 * Connects to database.
 */
function tinyConnect($host, $userName, $passWord, $dataBase)
{
    if (($con = mysql_connect($host, $userName, $passWord)) === false) {
        trigger_error('Failed to connect to database. Error: ' . mysql_error(), E_USER_ERROR);
        return false;
    }
    
    if (!mysql_select_db($dataBase, $con)) {
        trigger_error('Failed to select database. Error: ' . mysql_error($con), E_USER_ERROR);
        return false;
    }
    
    return $con;
}

/**
 * Disconects.
 */
function tinyDisconnect(&$db)
{
    if (mysql_close($db))
        unset($db);
    else 
        trigger_error('MySQL error: ' . mysql_error(), E_USER_WARNING);
}

/**
 * Do query.
 */
function tinyQuery($query)
{
    global $db;
    
    if (!($rez = mysql_query($query, $db))) {
        trigger_error('SQL Query error: ' . mysql_error(), E_USER_WARNING);
        return false;   
    }
    
    return $rez;
}

/**
 * Insert data to table.
 */
function tinyInsert($table, $fields)
{
    global $db;
    
    if (!is_array($fields)) {
        return false;
    }
    
    $sql = 'INSERT INTO `' . tinyEscape($table) . '` (';
    $tmp = 'VALUES (';
    
    foreach ($fields as $field => $value) {
        $sql .= '`' . tinyEscape($field) . '`, ';
        $tmp .= "'" . tinyEscape($value) . "', ";
    }
    $sql = substr($sql, 0, -2) . ') ' . substr($tmp, 0, -2) . ')';
    
    if (!mysql_query($sql, $db)) {
        trigger_error('SQL Query error: ' . mysql_error(), E_USER_WARNING);
        return false;   
    }
Thank you all
Reply With Quote
  #2 (permalink)  
Old 09-21-09, 01:19
mnirwan mnirwan is offline
Registered User
 
Join Date: Sep 2009
Posts: 64
I think your script was not pasted completely. From the snippet that you pasted, it looks like it's basically just do

Code:
INSERT INTO <some_table> VALUES
(a, b, c),
(d, e, f)
<etc>
;
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On