Reply To: RE: CID Lookup

VitalPBX Community Support General Discussion CID Lookup Reply To: RE: CID Lookup

    Posted by: Steve

    Any offers for an example using http/https?


    Would it be possible in a future release to “It would be nice if you could add field for direct SQL query.”

    Ah i see what you are trying to do now (from the comment you left on my question).

    Here’s a very quick example assuming you have a database on the same server as the php file, that contains nothing but names and numbers…. and we’ll call that database phonebook, with a table in it called numbers. In that table are 2 fields called contactName and telNumber I’m not going to clense the query or anything, so not suggested for use on a web facing server 😉

    //simple script that looks for a variable called query, connects to a local database and returns a value with no realy error checking.

    //first grab the query into a quick simple variable we can use ie; this.php?query=0123456789,
    $number = $_REQUEST['query'];

    //connect to a database
    mysql_connect("localhost","dbusername","dbpassword") or die("Error Connecting to DB");
    //select the database we want to use

    //build a simple query that returns the first matching record for the number we supplied
    $q = mysql_query("select * from `numbers` where `telNumber`='$number' LIMIT 1");
    //If you have found a result return the Name of the Person
    if(mysql_num_rows($q) > 0){
    //create an associative array of the feilds in the table for that record (ie it returns 'name' and 'telNumber' for the record in an array called a)
    $a = mysql_fetch_assoc($q);
    //output the contactName field for that record to the page
    echo $a['contactName'];
    //If there was Less than 1 result (ie 0), just return the number sent to the output
    echo $number;
    //close the connection to the database... You dont really need to do this, as when the page stops, it will close anyway. but on a busy server this will keep load down


    This is by no means the Best and most secure way to do it, But if you're doing this lookup locally and not on a web facing server then it will get you started. If it is web facing, this is a good starting point to learn from
    I can knock up a script that will work from CSV if working that way is better.
    Hope this helps :)