Jump to content

jaymc

Members
  • Posts

    1,521
  • Joined

  • Last visited

    Never

Everything posted by jaymc

  1. I usually define $my once at the top of the script that way I can use it inside of any function. The example you have given above still requires $my to be defined within the function requiring it I need something like this $my = new db_class("192.168.1.2", "root", "password", "db"); function cheese() { $q = $my->query("select * from users); } function beans() { $q = $my->query("select * from users); } function sausage() { $q = $my->query("select * from users); } Hence no mention of $my in any function in order to use it..
  2. I have extended the mysqli class like below $my = new db_class("192.168.1.2", "root", "password", "db"); Im new to classes so heres my question In order to use the $my to gain mysql functionality within another function outside of the class, do I have to call global $my at the start of the function like so function cheese() { global $my; $q = $my->query("select * from users); } I am kind of hoping I can use $my where ever and when ever I wish as long as the mysq.class.php file is included, without having to use global or $GLOBALS etc Is the way I have shown above the correct method?
  3. Is there also a way to do it in php though? For future refference as I have a few other things where your example is not relivent e.g. $q = "SHOW CREATE TABLE $dbName.$tableName" $doq = mysql_query($q); $data = mysql_fetch_assoc($doq); mysql_query($data[Create Table]); // This needs to be run in a different database to $dbName and do not want to regex or str_replace the create view of a table to inject a database name as $data[Create Table] returns the below CREATE TABLE `clients` ( `id` int(6) unsigned NOT NULL auto_increment, `companyName` varchar(50) NOT NULL, `credits` int(7) unsigned NOT NULL, `registered` datetime NOT NULL default '0000-00-00 00:00:00', `active` enum('0','1') NOT NULL default '1', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8
  4. Great idea! Overlooked that one
  5. I have made a database class to handle mysql queries etc One function I have made is to log mysql errors to a database table. The issue is that the error is logged into a primary database although the error may be generated while querying another database Primary Database = Master Querying Database = JohnSmiths Obviously to query JohnSmiths I must be currently selected into that database, however, if there is an error and an error needs to be inserted into Master I will have to select that database to insert The problem arrises when the next part of my script needs to query JohnSmiths, it cant as its current selected into Master due to logging the error Here is snipped of the code mysql_select_db("JohnSMiths"); mysql_query("selecttt * from table"); this is a bad query which will call sqlError(); ################ # LOG AN ERROR # ################ function sqlError($error) { mysql_select_db("Master"); // All errors are written to the Master database $enviroment = print_r($_SERVER, true); $session = print_r($_SESSION, true); $insert = "INSERT INTO mysql_errors values( NULL, '".$this->sqlSafe($error)."', '".$_SERVER['SCRIPT_FILENAME']."', '".$this->sqlSafe($enviroment)."', '".$this->sqlSafe($session)."', NOW())"; $this->sqlQuery($insert); } // Query JohnSmiths table mysql_query("Select * from table"); // This will be trying to look into MASTER table as I last selected that whilst logging the error. It needs to be querying the JohnSmiths table and obviously I cant call mysql_select_db() before every single query incase the previous one caused an error Any ideas what I can do here?
  6. jaymc

    user login

    I am creating a system which requires our customers to have there own database which contains 40+ tables One of those tables is a users table so they can add their own users with group priveleges etc All our customers users will login through the same interface (front end login page) My question is, whats the best way to authenticate the user without requiring: 1: company ID/username 2: users login email 3: password I have thought of two solutions but both I do not want to use Solution 1: carbon copy all our customers user details into a master table which is used to login. that way only login email and password required however Solution 2: User an authentication url to set a cookie containing the customer ID so all logins will use the customers database users table Solution 3: loop through all customers DB's querying their users table for the correct login email and password Any other ideas? If not, which of the above do you think is the best?
  7. From php.net. highlighted is the problem __FILE__ : The full path and filename of the file. If used inside an include, the name of the included file is returned. Since PHP 4.0.2,
  8. Wait sorry it doesn't do what I need <? // this php file exists in /home/jay/live/www/scripts/file.php // I want $dir to = /home/jay/live/www/scripts/ // not /home/jay/ include("/home/jay/global.php"); // this has $dir = dirname(__FILE__); echo $dir; ?>
  9. dirname(__FILE__) is what I was looking for Thanks.
  10. I use $_SERVER['DOCUMENT_ROOT'] to check the path of a script however I have just realised if you run a script outside of apache, $_SERVER variable does not contain anything So my question is, when running php script via cronjob or command line how can I retreive the document root of the file?
  11. jaymc

    Email remove

    That didnt work on this criteria $string = "hello john@hotmail. com you ok"; echo extract_email($string)";
  12. jaymc

    Email remove

    function extract_email($string) { $pattern = '/([a-z0-9])(([-a-z0-9._])*([a-z0-9-_]))*\@([a-z0-9])' . '(([a-z0-9-])*([a-z0-9]))+' . '(\.([a-z0-9])([-a-z0-9_-])?([a-z0-9\.])+)/i'; preg_match ($pattern, $string, $matches); return $matches['0']; } What I do is have it return the match and then use str_replace to replace the email address with "..."
  13. jaymc

    Email remove

    Hmm Can you give me an example to try?
  14. jaymc

    Email remove

    I have a script that uses regex to check a string for an email, if it finds it removes However, It obviously cant find emails that are typed like this Hello this is my email j o h n @ h o t m a i l . c o m please add it There are also other tricks but what is the best way to combat this?
  15. I use this Rule to enable me to call images from an external domain just by calling "/image" RewriteRule ^image/(.+)$ http://image.site.co.uk/$1 [R=301,L] It works fine so I can have <img src="/image/pic.jpg"> instead of <img src="http://image.site.co.uk/image/pic.jpg"> However, Im worried because of the redirect it will cause a lot of overhead? http://image.site.co.uk is actually lighttpd just for images but I guess the ReWrite means my apache will still essentially carry some of the load for images Should I be concerned? Is there a better way.. p.s - this is also to help with https:// warnings if you link an image from http
  16. I want to use mod_rewrite to treat this /image/pic.jpg as http://image.site.com/pic.jpg Any idea if this is possible? So I could have <img src="/image/pic.jpg"> in my code but in actual fact the image is served from http://image.site.com/pic.jpg
  17. Hmm that didn't appear to work. It just orders the data by DESC ignoring my defined order Heres the query SELECT `First Name`, `Mobile Phone`, `ID/Status` idstat FROM `example_innodb` GROUP BY `Mobile Phone` ORDER BY FIELD(`ID/Status`, 'Hot Prospect', 'Prospect', 'Be Back', 'Blow Out') DESC
  18. Lets say I have a field which contains the following entries, as enum for example Beans Lettuce Chocolate Onion Milk I want to order by Beans, Milk, Onion, Chocolate, Lettuce So not ASC or DESC, an order which is defined by data I input as shown above
  19. Yes, customers use MS excel so all their data will be converted to CSV so its universal
  20. This may be a stupid question but whats the best way to clean a mobile number from invalid chars without messing up the mobile itself Mobile numbers I am having to deal with are for example like this [44] 07783784123 [44] 07783-784-123 [44] 07 783 784 123 [07783784123] 447783784123 The end result must be 07783784123 Some mobiles can have 10/11 chars in, so it may be difficult to strip out all the bad characters and then just split leaving the last 11 chars..
  21. I have made a script in php that will read a CSV file and with that it will create a new table in mysql using the fields and data provided in the csv file. The issue I have is a file I used for testing contains 80 fields. At the moment I am just setting every field to varchar(700) regardless just to be on the safe side. However, mysql is complaining about 65000 limit on varchar combined. This also is not a good way as some fields may require more than 700 chars Whats the best way I can safely a csv field and data structure into mysql via code without having a buggy system which may fail if the data/fields in the csv file does not gel with my code...
  22. Not sure if any of your are familiar with ACT database? A lot of companies use it that deal with customer leads/sales etc Im wondering if php can be used to remote query it, kind of like how you would with mysql? Any useful info on it? Not got that far with google.. not really a hot subject I guess
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.