Raised This Month: $ Target: $400
 0% 

sql-problem


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
lagbeast
Junior Member
Join Date: Jul 2007
Old 07-03-2007 , 19:26   sql-problem
Reply With Quote #1

Hi everyone. Here is my problem. I am using a code-snipplet (after many failed attempts to make my own) and my problem is that the script says that there is no table in my db, but the table is there. Please tell my that im retarded and that i just missed something like that u cant use this on an mysql-server?

The errormessage that I get is "No such table db|1"

Here is the code:
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <dbi>


public plugin_init()
{
    
//Create a connection
    
new Sql:mysql dbi_connect("localhost""root""""mysql")

//If the connection is less than 1, it is bad   
    
if (mysql SQL_OK) {
        new 
err[255]
        new 
errNum dbi_error(mysqlerr254)
        
server_print("error1: %s|%d"errerrNum)
        return 
1
    
}
    
    
server_print("Connection handle: %d"mysql)
    
//Do a select query 
    
new Result:res dbi_query(mysql"SELECT * FROM db")

//If the query is greater than 0, you got a handle to the result set    
    
if (res <= RESULT_NONE) {
        new 
err[255]
        new 
errNum dbi_error(mysqlerr254)
        
server_print("error3: %s|%d"errerrNum)
        return 
1
    
}
    
    
server_print("Result handle: %d"res)

//Loop through the result set   
    
while (res && dbi_nextrow(res)>0) {
        new 
qry[32]
//Get the column/field called "keyname" from the result set
        
dbi_result(res"id"qry32)
        
server_print("result: %s"qry)
    }

//Free the result set   
    
dbi_free_result(res)

and my database looks like this

Code:
-- phpMyAdmin SQL Dump
-- version 2.6.1
-- http://www.phpmyadmin.net
-- 
-- Värd: localhost
-- Skapad: 03 juli 2007 kl 04:22
-- Serverversion: 4.1.9
-- PHP-version: 4.3.10
-- 
-- Databas: `mysql`
-- 
CREATE DATABASE `mysql` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
USE mysql;

-- --------------------------------------------------------


-- 
-- Struktur för tabell `db`
-- 

CREATE TABLE `db` (
  `Host` char(60) character set latin1 collate latin1_bin NOT NULL default '',
  `Db` char(64) character set latin1 collate latin1_bin NOT NULL default '',
  `User` char(16) character set latin1 collate latin1_bin NOT NULL default '',
  `Select_priv` enum('N','Y') NOT NULL default 'N',
  `Insert_priv` enum('N','Y') NOT NULL default 'N',
  `Update_priv` enum('N','Y') NOT NULL default 'N',
  `Delete_priv` enum('N','Y') NOT NULL default 'N',
  `Create_priv` enum('N','Y') NOT NULL default 'N',
  `Drop_priv` enum('N','Y') NOT NULL default 'N',
  `Grant_priv` enum('N','Y') NOT NULL default 'N',
  `References_priv` enum('N','Y') NOT NULL default 'N',
  `Index_priv` enum('N','Y') NOT NULL default 'N',
  `Alter_priv` enum('N','Y') NOT NULL default 'N',
  `Create_tmp_table_priv` enum('N','Y') NOT NULL default 'N',
  `Lock_tables_priv` enum('N','Y') NOT NULL default 'N',
  PRIMARY KEY  (`Host`,`Db`,`User`),
  KEY `User` (`User`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='Database privileges';

-- --------------------------------------------------------
lagbeast is offline
lagbeast
Junior Member
Join Date: Jul 2007
Old 07-04-2007 , 08:37   Re: sql-problem
Reply With Quote #2

Does anyone have any ideas?
lagbeast is offline
raa
Senior Member
Join Date: Oct 2005
Old 07-04-2007 , 14:39   Re: sql-problem
Reply With Quote #3

This is how one of my plugins connects
Code:
#define MAX_NAME_LENGTH 31 new g_host[MAX_NAME_LENGTH+1], g_user[MAX_NAME_LENGTH+1], g_pass[MAX_NAME_LENGTH+1], g_dbname[MAX_NAME_LENGTH+1], g_error[MAX_NAME_LENGTH+1] public function() { g_dbc = dbi_connect(g_host,g_user,g_pass,g_dbname,g_error,MAX_NAME_LENGTH) }
__________________
raa is offline
lagbeast
Junior Member
Join Date: Jul 2007
Old 07-04-2007 , 16:33   Re: sql-problem
Reply With Quote #4

Do you think its the connection thats the problem or is it the part of selecting a table? Does anyone have a fail-safe way to connect and read a line from a sql-table. Easy and simple? If you do please paste it here. Thx a lot!
lagbeast is offline
Old 07-04-2007, 19:33
mysticssjgoku4
This message has been deleted by mysticssjgoku4. Reason: im wrong
mysticssjgoku4
Veteran Member
Join Date: Jan 2005
Location: Chicago Heights, IL
Old 07-04-2007 , 19:35   Re: sql-problem
Reply With Quote #6

ius the table "db" in the DATABASE "mysql" ?
__________________

mysticssjgoku4 is offline
Send a message via AIM to mysticssjgoku4 Send a message via MSN to mysticssjgoku4
lagbeast
Junior Member
Join Date: Jul 2007
Old 07-04-2007 , 20:07   Re: sql-problem
Reply With Quote #7

yes
lagbeast is offline
lagbeast
Junior Member
Join Date: Jul 2007
Old 07-04-2007 , 20:33   Re: sql-problem
Reply With Quote #8

Alright. I used hawks code instead and it works now. Now ive been looking here http://www.amxmodx.org/funcwiki.php?go=func&id=1105 at the SQLReadResult, and i get it working, now i just dont know how to get out the info.

PHP Code:
 // run a random query
    
new Handle:Query SQL_PrepareQuery(SqlConnection,"SELECT * FROM login")
 
    
// run the query
    
if(!SQL_Execute(Query))
    {
        
// if there were any problems
        
SQL_QueryError(Query,g_Error,511)
        
set_fail_state(g_Error)
    }
 
    
// checks to make sure there's more results
    // notice that it starts at the first row, rather than null
    
new Data
    
while(SQL_MoreResults(Query))
    {
        
// columns start at 0
        
Data SQL_ReadResult(Query,1)
 
        
server_print("Found data: %d",Data)
        
SQL_NextRow(Query)
    } 
Example: I have a table named login and i want to get out the info in the second column called nick and i want to store that info in a string. How the hell do i do that?
lagbeast is offline
lagbeast
Junior Member
Join Date: Jul 2007
Old 07-05-2007 , 09:53   Re: sql-problem
Reply With Quote #9

Noone has an idea?
lagbeast is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 07-05-2007 , 10:05   Re: sql-problem
Reply With Quote #10

PHP Code:
new nick[64];
SQL_ReadResult(Query,SQL_FieldToNum(Query,"nick"),nick,63); 
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
Reply


Thread Tools
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 On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 21:26.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode