0

The code below is supposed to use class data setup in sqlClass.php, but I am getting an "Undefined class constant 'getHost' error when running the script. Should I be putting the require_once somewhere else if it's being used within a function?

getHost, getSqlUser, and getSqlPassword are defined in sqlClass.php

<?php
use CallFire\Api\Rest\Request;
use CallFire\Api\Rest\Response;
require 'autoload.php';
require_once('shannonTeslaApiKey.php');
require_once('sqlClass.php');


/*creates executeSql function, which opens connection to db and inserts orderId into order_verify table */
function addRowToVerifyOrder($anOrderNumber, $aStatus, $someDIDs) {

    $dbConnection = mysql_connect(CallFireSqlTokens::getHost, CallFireSqlTokens::getSqlUser, CallFireSqlTokens::getSqlPassword)
    or die('Could not connect: ' . mysql_error());
    mysql_select_db('opsnumberorder') or die('Could not select database');

    $someSql = 'INSERT INTO verify_order VALUES('. $anOrderNumber .', "'. $aStatus .'", now(), '. $someDIDs .')';
    /*DEBUGGING TOOL
    echo "sql is " . $someSql;*/

    $result = mysql_query($someSql) or die('Query failed: ' . mysql_error());

    //mysql_free_result($result);
    mysql_close($dbConnection);

    return $result;
}
Seymour
  • 7,043
  • 12
  • 44
  • 51
ObiWanShanobi
  • 442
  • 1
  • 5
  • 10
  • Add the code for `CallFireSqlTokens` class – user20232359723568423357842364 Dec 10 '13 at 22:00
  • 1
    Is it a method rather than a constant? Like `CallFireSqlTokens::getHost()`? – jszobody Dec 10 '13 at 22:15
  • Without the code for `CallFireSqlTokens` we can only assume that getHost is a constant and if so PHP is telling you that there is no such constant in that class with that name. – user555 Dec 10 '13 at 22:16
  • 1
    Also, please, [don't use mysql_* functions in new code](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). They are no longer maintained and are officially deprecated. Learn about [prepared statements](http://en.wikipedia.org/wiki/Prepared_statement) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) — [this article](http://php.net/manual/en/mysqlinfo.api.choosing.php) will help you decide which. If you choose PDO, [here is a good tutorial](http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers). – user555 Dec 10 '13 at 22:17
  • `mysql_connect`? `or die()`? What kind of tutorials are you kids reading these days? Do you not look at the 10+ year old article date and think *"Hmm, maybe there's a more recent tutorial around"*? – Phil Dec 10 '13 at 23:03
  • Also, @jszobody is most probably correct with that assumption – Phil Dec 10 '13 at 23:05

0 Answers0